package com.dianda.controller;

import com.dianda.pojo.Classmate;
import com.dianda.pojo.News;
import com.dianda.pojo.NewsResult;
import com.dianda.pojo.Result;
import com.dianda.service.ClassmateService;
import com.dianda.service.NewsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class NewsController {

    @Autowired
    NewsService service;

    @PostMapping("/app5/news/list")
    public NewsResult getNewsList() {
        List<News> list = service.getNewsList();
        NewsResult r = new NewsResult();
        if (list != null) {
            r.setSuccess(true);
            r.setMsg("成功");
            r.setList(list);
        }else{
            r.setSuccess(false);
            r.setMsg("失败");
        }
        return r;
    }
    @PostMapping("/app6/news/findone")
    public NewsResult getNewsById(@RequestBody News news){
        News news1=service.getNewsById(news.getId());
        System.out.println(news1.getId()+" "+news1.getTitle());
        NewsResult r=new NewsResult();
        if (news1 != null) {
            r.setSuccess(true);
            r.setMsg("成功");
            r.setData(news1);
        }else{
            r.setSuccess(false);
            r.setMsg("失败");
        }
        return r;
    }
}
